<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('入库交接班统计')"/>
    <link th:href="@{/assets/libs/layui/css/layui.css}" media="all" rel="stylesheet">
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('班次') != -1">
                            班次：
                            <select name="pid">
                                <option value="">全部</option>
                                <option v-for="(item, index) in jobTimes" :key="index" :value="item.pid" v-cloak>{{item.planName}}</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('单据号') != -1">
                            单据号：<input type="text" id="billNo" name="billNo"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('物料名称') != -1">
                            物料名称：
                            <select name="itemId">
                                <option value="">全部</option>
                                <option v-for="(item, index) in items" :key="index" :value="item.itemId" v-cloak>{{item.itemName}}</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('入库类型') != -1">
                            入库类型：
                            <select name="type">
                                <option value="">全部</option>
                                <option v-for="(item, index) in inTypes" :key="index" :value="item.dictValue" v-cloak>{{item.dictLabel}}</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('状态') != -1">
                            状态：
                            <select name="state">
                                <option value="">全部</option>
                                <option value="1">未审核</option>
                                <option value="2">审核通过</option>
                                <option value="3">正在入库</option>
                                <option value="4">入库完成</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('操作人员') != -1">
                            操作人员：<input type="text" name="createUserName"/>
                        </li>
                        <li class="select-time" v-show="checkedSearch.indexOf('操作时间') != -1">
                            <label>操作时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "in/billInPlan";

    const searchOptions = ['班次', '单据号', '物料名称', '入库类型', '状态', '操作人员','操作时间'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['班次', '物料名称', '入库类型', '状态'],
            searches: searchOptions,
            isIndeterminate: true,
            jobTimes: [],
            inTypes: [],
            items: []
        },
        methods: {
            getItems: function(){
                var that = this;
                var item = that.item;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/itemInfo/findList",
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.items = data.rows;
                    }
                });
            },
            getInTypes: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    url: '/system/dict/data/list',
                    type: 'POST',
                    data: {
                        dictType: 'put_goods_type'
                    },
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.inTypes = data.rows;
                    }
                })
            },
            getJobTimes: function(){
                var that = this;
                $.ajax({
                    cache: true,
                    url: '/planset/findList',
                    type: 'POST',
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        let rows = data.rows;
                        for(var row of rows){
                            if(row["totalTime"] != "0"){
                                that.jobTimes.push(row);
                            }
                        }
                    }
                })
            },
            moreSearch(){
                this.showMore = true;
            },
            handleCheckAllChange(val){
                this.checkedSearch = val ? searchOptions : [];
                this.isIndeterminate = false;
            },
            handleCheckedSearchChange(value){
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.searches.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.searches.length;
            }
        },
        created(){
            this.getItems();
            this.getInTypes();
            this.getJobTimes();
        }
    })

    $(function() {
        var options = {
            url: prefix + "/list",
            modalName: "入库交接班统计",
            columns: [
                {
                    field: 'planName',
                    title: '班次',
                    align: 'center'
                },
                {
                    field: 'billNo',
                    title: '单据号',
                    align: 'center'
                },
                {
                    field: 'itemName',
                    title: '物料名称',
                    align: 'center',
                },
                {
                    field: 'typeName',
                    title: '入库类型',
                    align: 'center'
                },
                {
                    field: 'distributionNum',
                    title: '行号',
                    align: 'center',
                    formatter: function(value, row, index){
                        if(value == '' || value == null){
                            return "-";
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field: 'quantity',
                    title: '计划总数',
                    align: 'center',
                },
                {
                    field: 'benCiRuKu',
                    title: '该行号入库量',
                    align: 'center',
                },
                {
                    field: 'quantityReceived',
                    title: '实际入库数',
                    align: 'center',
                },
                {
                    field: 'state',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        if(value === 1){
                            return "未审核";
                        }else if(value === 2){
                            return "审核通过";
                        }else if(value === 3){
                            return "正在入库";
                        }else if(value === 4){
                            return "入库完成";
                        }
                    }
                },
                {
                    field: 'createUserName',
                    title: '操作人员',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '操作时间',
                    align: 'center',
                    sortable: true,
                    formatter: function(value, row, index){
                        return value.slice(0, 19)
                    }
                }
            ]
        };
        $.table.init(options);
    });
</script>
</body>
</html>
